<?php

/**
 * MyProjectNameHere <http://www.example.com>
 * Model Class
 *
 * It is recommended to extend Model classes from WWW_Factory in order to 
 * provide various useful functions and API access for the Model.
 *
 * @package    Factory
 * @author     DeveloperNameHere <email@example.com>
 * @copyright  Copyright (c) 2012, ProjectOwnerNameHere
 * @license    Unrestricted
 * @tutorial   /doc/pages/guide_mvc.htm
 * @since      1.0.0
 * @version    1.0.0
 */

class WWW_model_doctor extends WWW_Factory {

	/**
	 * It is recommended to define all data variables here. Usually the 
	 * data variables have the same names as the column names of database 
	 * rows from a table.
	 */	
	public $conn;
	/**
	 * Alternative to __construct()
	 *
	 * WWW_Factory does not allow to overwrite __construct() method, so 
	 * this __initialize() is used instead and loaded automatically when 
	 * object is created.
	 *
	 * @return boolean
	 */
	public function __initialize(){
		require('engine/class.www-database.php');
		$this->conn=new WWW_Database();				
		// Do something here
		return true;
		
	}
	
	/**
	 * This is intended to load data from database
	 *
	 * @param integer $id identifier of the object loaded
	 * @return boolean
	 */
	
	public function create_category($data){
		//extract($_POST);
		$query = "insert into `doctors_category` (category,admin_id,created_date,updated_date) VALUES ('".$data['category_name']."','".$data['admin_id']."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."')";
		print_r($query);exit;
		$data=$this->conn->dbCommand($query);		
		if($data){
			return array('message'=>'Successfully Created');			
		}else{
			return array('message'=>'Creation Failed');
		}	
	}
	public function update_category(){
		extract($_POST);
		$data=$this->conn->dbCommand("update doctors_category set category='".$category."' where id=".$id);		
		if($data){
			return array('message'=>'Update Successfully');			
		}else{
			return array('message'=>'Updates Failed');
		}	
	
	}
	public function all_categories(){
		$result=$this->conn->dbMultiple("select * from doctors_category ");
		if($result){
			$totalrows = $this->conn->dbSingle('SELECT FOUND_ROWS() as rows;');
		return array('message'=>"All Categories","info"=>$result,'total'=>$totalrows);
		}
		else
		return array('message'=>'No Categories');
		
	}
	public function get_category(){
		extract($_POST);		
		$result=$this->conn->dbSingle("select *from doctors_category where id=".$id);
		if($result)
		return array('message'=>"Category Info",'info'=>$result);
		else
		return array('message'=>'No Categories');
	}
	public function create(){
		extract($_POST);		
		$data=$this->conn->dbCommand("INSERT INTO `doctors` (`category_id`, `doctor_name`, `hospital_name`, `heading`, `email`, `phone`, `web`, `created_by`, `create_date`,`status`, `address`, `fax`, `logo`, `youtube`)	VALUES (".$category_id.", '".$doctor_name."', '".$hospital_name."', '".$heading."', '".$email."', '".$phone."', '".$web."', ".$created_by.", NOW(), '1', '".$address."', '".$fax."', '".$logo."', '".$youtube."')");		
		if($data){
			return array('message'=>'Successfully Created');			
		}else{
			return array('message'=>'Creation Failed');
		}	
	}
	public function update(){
		extract($_POST);
		$data=$this->conn->dbCommand("UPDATE `doctors` set `category_id`=".$category_id.", `doctor_name`='".$doctor_name."',
 `hospital_name`='".$hospital_name."',`heading`='".$heading."', `email`='".$email."',`phone`='".$phone."', `web`='".$web."',
 `updated_by`='".$updated_by."', `updated_date`=NOW(),  `address`='".$address."', `fax`='".$fax."', `logo`='".$logo."', `youtube`='".$youtube."'  where id=".$id);		
		if($data){
			return array('message'=>'Updated Successfully');			
		}else{
			return array('message'=>'Updates Failed');
		}	
	
	}
	public function all(){
		extract($_POST);
		$status = ($status=='')?'':" where status='1'";
		$result=$this->conn->dbMultiple("select * from doctors".$status);
		if($result){
			$totalrows = $this->conn->dbSingle('SELECT FOUND_ROWS() as rows;');
		return array('message'=>"All Doctors","info"=>$result,'total'=>$totalrows);
		}
		else
		return array('message'=>'No Doctors');
		
	}
	public function get(){
		extract($_POST);		
		$result=$this->conn->dbSingle("select *from doctors where id=".$id);
		if($result)
		return array('message'=>"Doctor Info",'info'=>$result);
		else
		return array('message'=>'Doctor Not Found');
	}
	public function get_category_doctors(){
		extract($_POST);
		$result=$this->conn->dbMultiple("select * from doctors where category_id=".$category_id." and status='1'");
		if($result){
			$totalrows = $this->conn->dbSingle('SELECT FOUND_ROWS() as rows;');
		return array('message'=>"Category Doctors","info"=>$result,'total'=>$totalrows);
		}
		else
		return array('message'=>'Not Found Doctors');
	}
	public function disabled_doctor(){
		extract($_POST);		
		$statusRequest = ($status=='0')?"Inactive":"Activated";
		$data=$this->conn->dbCommand("UPDATE `doctors` set status='".$status."' where id=".$id);
		if($data)
			return array('message'=>$statusRequest." Successfully");		
		else
			return array('message'=>$statusRequest.' Fails');
	   	
	}
	public function delete_doctor(){
		extract($_POST);
		$data=$this->conn->dbCommand("delete from `doctors` where id=".$id);
		if($data)
			return array('message'=>"Deleted Successfully");		
		else
			return array('message'=>'Deletion Fails');
	}
}
	
?>